package com.yangxin.lesson.web.controller;

import com.yangxin.lesson.entity.SysUser;
import com.yangxin.lesson.service.UserService;
import com.yangxin.lesson.vo.request.RegisterRequestVo;
import com.yangxin.lesson.vo.request.UpdateUserRequestVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * @Filename UserController.java
 * @Author yangxinxin
 * @Description
 * @Date 2020/2/10 11:28
 * @Param
 * @return
 **/

@RestController
@RequestMapping("/api")
@Api(tags = "用户模块",description = "用户相关模块接口")//可以在页面中显示，可以配置多个，
                                                        // 当配置多个信息的时候，在页面中会显示
                                                        //多个接口的信息

//@ApiOperation用在controller里的方法上，说明方法的作用，每一个接口的定义
public class UserController {
    @Autowired
    private UserService userService;
    //@ApiParam用于controller中方法的参数说明
    @GetMapping("/getUser")//required = true表示必填
    @ApiOperation(value = "获取用户详细信息接口")
    //@ApiResponse用于方法上说明接口响应的一些信息
    @ApiResponses(
            {
                    @ApiResponse(code = 0,message = "响应成功",response = SysUser.class)
            }
    )
    public SysUser getUserDetail(@ApiParam(value = "用户Id",required = true) @RequestParam String id){
        return  userService.getUserInfo(id);
    }
//result风格
    // Get查看
    @GetMapping("/user/{id}")
    @ApiOperation(value = "RESTful风格获取用户信息接口")
    @ApiResponses(
            {
                    @ApiResponse(code = 0,message = "响应成功",response = SysUser.class)
            }
    )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户ID",dataType = "String",paramType = "query",required = true,
            defaultValue = "81f21784-64dd-45a0-bff4-d8d7477b3be4")
    })
    public SysUser getUserInfo(@PathVariable("id") String id){
        return  userService.getUserInfo(id);
    }
    //Post增加
    @PostMapping("/user")
    @ApiOperation(value = "增加用户信息接口")
    @ApiResponses({
            @ApiResponse(code = 0,message = "响应成功",response = SysUser.class)
    })
    public String insertUser(@RequestBody RegisterRequestVo vo){
        return  userService.register(vo);
    }
    //Put更新
    @PutMapping("/user")
    @ApiOperation(value = "更新用户信息接口")
    @ApiResponses({
            @ApiResponse(code = 0,message = "响应成功！",response = SysUser.class)
    })
    public  String updateUserInfo(@RequestBody UpdateUserRequestVo vo){
        return userService.updateUserInfo(vo);
    }
    //Delete删除
    @DeleteMapping("/user/{id}")
    @ApiOperation(value = "删除用户信息的接口")
    @ApiResponse(code = 0,message = "响应成功！",response = SysUser.class)
    public  String deleteUserInfo(@PathVariable("id") String id){
        return userService.deelteUserInfo(id);
    }

}
